package com.bole.lambda;

import java.util.function.*;

/**
 * @author: 叶子
 * @date: 2022/04/10 17:12
 * jdk自带的一些FunctionInterface(只有一个抽象方法的接口)
 **/
public class JdkFunctionDemo {
    public static void main(String[] args) {
        //Supplier 没有输入，只有一个输出
        Supplier<String> supplier = () -> "this is Supplier demo";
        System.out.println(supplier.get());//调用Supplier的get方法才能得到结果
        //Consumer 只有一个输入，没有输出
        Consumer<String> consumer = i -> System.out.println("this is demo for " + i);
        consumer.accept("Consumer");
        //Function 输入T 输出R
        Function<Integer, Integer> function = i -> i * i;
        System.out.println("Function demo:" + function.apply(9));
        //Function的输入和输出类型相同时，可以用UnaryOperator
        UnaryOperator<Integer> unaryOperator = i -> i * i;
        System.out.println("UnaryOperator demo:" + unaryOperator.apply(9));
        //BiFunction<T,U,R> 输入T、U，输出R
        BiFunction<Integer, Integer, String> biFunction = (i, j) -> i + "*" + j + "=" + i * j;
        System.out.println(biFunction.apply(3, 7));
    }
}